package com.shuw.com.beingfortextproject.api;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

/**
 * Created by ${cs} on 2018/4/27.
 */

public class IntegerDefaultAdapter implements JsonSerializer<Integer>,JsonDeserializer<Integer> {

	@Override
	public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
		if (json.getAsString().equals("")){
			return 0;
		}
		return json.getAsInt();
	}

	@Override
	public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
		return new JsonPrimitive(src);
	}
}
